package com.fowo.api.controller.shipment.wfs;

import com.fowo.api.model.platformshipping.PlatformshippingReleaseInventoryAction;
import com.fowo.api.model.platformshipping.PlatformshippingVo;
import com.fowo.api.service.impl.PlatformshippingServiceImpl;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

@Component
public class platformshippingReleaseInventoryAction implements PlatformshippingReleaseInventoryAction {

    @Resource
    private PlatformshippingServiceImpl platformshippingService;

    //释放库存
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void run(List<Long> idList) throws Exception {
        for(int i=0;i<idList.size();i++){
            handle(idList.get(i));
        }
    }
//释放库存
    private void handle(Long aLong) throws Exception {
        PlatformshippingVo voById = platformshippingService.getVoById(aLong);
        Assert.isTrue(voById.getIsinventorylocked().equals("0"),"违规操作");
        voById.setShippingstatus("0");
        //修改已发货
        platformshippingService.updateById(voById);
        //取消锁库存
        platformshippingService.cancelLocksInventory(aLong);
        platformshippingService.cancelLockpInventory(aLong);
        voById.setIsinventorylocked("1");
        platformshippingService.update(voById);
    }



}
